from flask import Flask, request
from flask_restful import Api, Resource

# 参考博客 http://www.bjhee.com/flask-ext1.html
app = Flask(__name__)
#
api = Api(app)

USER_LIST = {
    '1': {'name': 'Michael'},
    '2': {'name': 'Tom'},
}


class User(Resource):
    def get(self, user_id):
        return USER_LIST[user_id]

    def delete(self, user_id):
        del USER_LIST[user_id]
        return ''

    def put(self, user_id):
        USER_LIST[user_id] = {'name': request.form['name']}
        return USER_LIST[user_id]


api.add_resource(User, '/users/<user_id>')

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
